<?php require_once('../src/session_start.inc.php'); ?>
<?php $selected='alerte'; require_once('admin_header.php'); ?>
<?php
require_once('../src/functions.php');
require_once('../src/alerte_mail.class.php');
$alerte_mail = new alerte_mail();

if (isset($_GET['do_purge'])) {
	$nb = $alerte_mail->purge();
	header('Location: alerte_mail.php?purge=' . $nb);
}

$data = $alerte_mail->getAll();
?>

<h2>Alerte mail</h2>

<?php if (empty($data)) echo 'Aucune donnée'; else { ?>

<?php if (isset($_GET['purge']) && $_GET['purge']!=''): ?>
	<p class="message">La purge a supprimé <?php echo $_GET['purge'] . '&nbsp;' . wordPluriel('alerte', $_GET['purge']) ?>.</p>
<?php else: ?>
	<p><a href="alerte_mail.php?do_purge">Purger les alertes <b>non activées</b> depuis plus de <?php echo ALERTE_NB_DAYS . '&nbsp;' . wordPluriel('jour', ALERTE_NB_DAYS) ?></a></p>
<?php endif; ?>

<table>
	<tr>
		<th>mail</th>
		<th>nom complet</th>
		<th>activé&nbsp;?</th>
		<th>crée le</th>
		<th>nb d'annonces<br/>envoyées</th>
	</tr>
	<?php foreach($data as $value): ?>
	<tr>
		<td><?php echo '<a href="mailto:' . $value['mail'] . '">' . $value['mail'] . '</a>'; ?></td>
		<td><?php echo $value['civilite'] .' '. $value['prenom'] .' '. strtoupper($value['nom']); ?></td>
		<td class="center">
			<?php if ($value['is_active']==1) echo 'oui'; else echo 'non'; ?>
		</td>
		<td><?php echo usToFrDate($value['created_at'], true); ?></td>
		<td><?php echo $value['compteur']; ?></td>
	</tr>
	<?php endforeach; ?>
</table>

<?php } ?>

<?php require_once('admin_footer.php'); ?>